﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Leo.Blog.Model;
using System.Data.Entity;

namespace Leo.Blog.DAL.SysModule
{
    public class Sys_RoleModule_D : BaseRepository<Sys_RoleModule>
    {
        public bool SaveRoleModule(int RoleId, List<Sys_RoleModule> list)
        {
            BlogEntities BlogDb = new BlogEntities();
            IQueryable<Sys_RoleModule> roleModules=BlogDb.Sys_RoleModule.Where(m=>m.RoleId==RoleId);
            foreach (var roleModule in roleModules) {
                BlogDb.Entry<Sys_RoleModule>(roleModule).State= EntityState.Deleted;
            }
            foreach (var item in list) {
                BlogDb.Entry<Sys_RoleModule>(item).State = EntityState.Added;
            }
            return BlogDb.SaveChanges() > 0;
        }
    }
}
